SRCDIR0 = .
SRCDIR1 = net
SRCINC = . 
OBJDIR0 = .
OBJDIR1 = net
LIBDIR = .

CFLAGS:= -std=c++11 -g -Wall -Werror -Wno-deprecated -I.. -fPIC -I/usr/local/include
LDFLAGS:= -lpthread -levent -lglog -lgflags -shared -fPIC
TARGET:=libchi.so

SRC0 := $(wildcard $(SRCDIR0)/*.cc)
SRC1 := $(wildcard $(SRCDIR1)/*.cc)

OBJS0 := $(patsubst $(SRCDIR0)/%.cc, $(OBJDIR0)/%.o, $(SRC0))
OBJS1 := $(patsubst $(SRCDIR1)/%.cc, $(OBJDIR1)/%.o, $(SRC1))

DEPS = $(SRC:.cc=.d) 
.PHONY : all deps clean veryclean install objs

all : $(TARGET)

deps : $(DEPS)

objs : $(OBJS)

$(OBJS0) : $(OBJDIR0)/%.o : $(SRCDIR0)/%.cc
	$(CXX) -c $(CFLAGS) -I $(SRCINC) $< -o $@

$(OBJS1) : $(OBJDIR1)/%.o : $(SRCDIR1)/%.cc
	$(CXX) -c $(CFLAGS) -I $(SRCINC) $< -o $@

install:
	mkdir -p /usr/local/include/chi
	cp *.h /usr/local/include/chi
	mkdir -p /usr/local/include/chi/net
	cp net/*.h /usr/local/include/chi/net
	cp $(TARGET) /usr/local/lib

clean:
	rm -f $(OBJDIR0)/*.o $(OBJDIR1)/*.o
	rm -f *.d
	rm -f $(LIBDIR)/$(TARGET)

$(TARGET) : $(OBJS0) $(OBJS1)
	$(CXX) $(LDFLAGS) -o $(TARGET) $(OBJS0) $(OBJS1)
